package org.teremail.provider;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.google.inject.Provider;
import com.google.inject.ProvisionException;

public class ResourcePropertiesProvider implements Provider<Properties> {

    private final String resource;

    public ResourcePropertiesProvider(String resource) {
        this.resource = resource;
    }
    
    @Override
    public Properties get() {
        try {
            System.out.println("Loading Properties");
            Properties properties = new Properties();
            InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(resource);
            properties.load(resourceAsStream);
            return properties;
        } catch (IOException e) {
            throw new ProvisionException("Failed to load properties from resource: " + 
                    resource + " because: " + e.getMessage(), e);
        }
    }

}
